package com.hmall.api.config;

import com.hmall.api.client.fallback.PayClientFallback;
import com.hmall.common.utils.UserContext;
import feign.Logger;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Bean;

public class DefaultFeignConfig {

    @Bean
    public Logger.Level feignLogLevel(){
        return Logger.Level.FULL;
    }

    @Bean
    public RequestInterceptor userInfoRequestInterceptor(){
        return new RequestInterceptor() {
            @Override
            public void apply(RequestTemplate requestTemplate) {
                Long UserId = UserContext.getUser();
                if(UserId!=null) {
                    requestTemplate.header("user-info", UserId.toString());
                }
            }
        };//匿名内部类，就是直接创建一个拥有新方法的子类对象

    }

    @Bean
    public PayClientFallback payClientFallback(){return new PayClientFallback();}
    //后备方案需要注入


}